﻿/**********************************************************
 ●项目：Smartkernel
 ●公司：智能核心信息技术研发中心
 ●作者：曹艳白
 ●邮箱：caoyanbai@gmail.com
 ●创建：2008-08-10
**********************************************************/
using System;

namespace Smartkernel
{
    /// <summary>
    /// 消息队列中的实体
    /// </summary>
    [Serializable]
    public class SmartMessageEntity
    {
        private string label;
        /// <summary>
        /// 消息实体的标签
        /// </summary>
        public string Label { get { return this.label; } }

        private string body;
        /// <summary>
        /// 消息实体的正文
        /// </summary>
        public string Body { get { return this.body; } }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="label">标签</param>
        /// <param name="body">正文</param>
        public SmartMessageEntity(string label, string body)
        {
            this.label = label;
            this.body = body;
        }
        /// <summary>
        /// 重写Equals方法，注意，标签相同就认为是同一个消息实体
        /// </summary>
        /// <param name="obj">比较的对象</param>
        /// <returns>比较的结果</returns>
        public override bool Equals(object obj)
        {
            SmartMessageEntity other = obj as SmartMessageEntity;
            if (other == null)
            {
                return false;
            }
            else
            {
                return other.Label == this.Label;
            }
        }
        /// <summary>
        /// 重写GetHashCode，注意，以标签的哈希码为消息实体的哈希码
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            return this.label.GetHashCode();
        }
    }
}
